//
//  ConfirmVC.m
//  saler-ios
//
//  Created by 王亚陆 on 17/6/6.
//  Copyright © 2017年 sayimba. All rights reserved.
//

#import "ConfirmVC.h"
#import "PriceCell.h"
#import "AddCarCell.h"
#import "HomeVC.h"
@interface ConfirmVC ()
<UITableViewDelegate,
UITableViewDataSource,
UITextFieldDelegate,
UITextViewDelegate,
UIScrollViewDelegate,
UIGestureRecognizerDelegate
>
{
    UIImageView * nav;
    UITableView * PriceTable;
    UITableView * CarInforTable;
    RootViewController * TabBar;
    
    NSMutableArray * PriceArrData;
    NSMutableArray * CarInforData;
    
    UILabel * standardPrice;
    UITextField * field;
    
    
    UILabel * begainAddressLabel;
    UILabel * endAddressLabel;
    UILabel * chooseTimeLabel;
    NSString * priceStr;
    UIButton * priceBtn;
    
}
@property (nonatomic,strong) UIScrollView * ScrollView;

@property (nonatomic,strong) UIView * backview1;
@property (nonatomic,strong) UIView * backview2;
@property (nonatomic,strong) UITextField * PriceField;
@property (nonatomic,strong) UIImageView * backField;

@end

@implementation ConfirmVC

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.inforDic = [[NSMutableDictionary alloc]init];
        self.handDic = [[NSMutableDictionary alloc]init];
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    nav = [self createNav:@"物流信息"];
    [self.view addSubview:nav];
    self.view.backgroundColor = UIviewBackColor;
    
    PriceArrData = [[NSMutableArray alloc]init];
    CarInforData = [[NSMutableArray alloc]init];
    
    
    //    data =     {
//        carryToolId = 4;
//        carryToolName = "\U5355\U6392";
//        feeBOS =         (
//                          {
//                              name = "\U8fd0\U8d39";
//                              value = "6600.00\U5143";
//                          },
//                          {
//                              name = "\U4fdd\U9669\U8d39";
//                              value = "3.51\U5143";
//                          },
//                          {
//                              name = "\U91cc\U7a0b";
//                              value = "1758.23\U516c\U91cc";
//                          }
//                          );
//        lineId = 6;
//        ltlGrossPrice = 2200;
//        ltlUnitPrice = "1.3";
//        mileage = "1758.23";
//        programId = 1;
//        standardSalePrice = "6603.51";
//        tlGrossPrice = 2000;
//        tlUnitPrice = "1.17";
//        transModeCode = road;
//        transModeName = "road\U540d\U79f0\U6d4b\U8bd5";
//        unitPrice = "1.17";
//    };

    [self createScroll];
    [self createBackview1];
    [self createBackview2];
    [self createBtn]; //确定发车
    //创建输入价格
    [self createFieldView];
}


-(void)createFieldView{
    
    _backField = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, Main_Width, Main_height)];
    _backField.backgroundColor = RGBACOLOR(0, 0, 0, 0.3);
    _backField.hidden = YES;
    _backField.userInteractionEnabled = YES;
    
    // 当前顶层窗口
//    UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
//    // 添加到窗口
//    [window addSubview:_backField];
    [self.view addSubview:_backField];
    UITapGestureRecognizer * TapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ProBackTouch)];
    TapGesture.delegate = self;
    [_backField addGestureRecognizer:TapGesture];
    
    
    UIView * fieldView = [[UIView alloc]init];
    fieldView.backgroundColor = WhiteColor;
    [_backField addSubview:fieldView];
    [fieldView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_backField.mas_centerX);
        make.centerY.mas_equalTo(_backField.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(Main_Width-100*kWidth, 150*kHeight));
    }];
    
    
    UILabel * label = [UILabel createUIlabel:@"建议售价" andFont:FontOfSize19 andColor:TitleColor];
    [fieldView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(fieldView.mas_centerX);
        make.top.mas_equalTo(fieldView.mas_top).with.offset(10*kHeight);
    }];
    
    field = [[UITextField alloc]init];
    field.frame = CGRectMake(14*kWidth, CGRectGetMaxY(label.frame), Main_Width-100*kWidth, 200*kWidth);
    field.delegate = self;
    field.backgroundColor = WhiteColor;
    field.font = Font(FontOfSize19);
    field.textColor = BlackColor;
    field.textAlignment = NSTextAlignmentLeft;
    field.keyboardType = UIKeyboardTypeNumberPad;
    field.returnKeyType = UIReturnKeyDone;
    
    NSString * standardSalePrice= [NSString stringWithFormat:@"%@",_inforDic[@"standardSalePrice"]];
    field.placeholder = standardSalePrice;
    [fieldView addSubview:field];
    
    
    UILabel * price4 = [UILabel createUIlabel:@"￥" andFont:FontOfSize19 andColor:PriceBigColor];
    [_backField addSubview:price4];
    [price4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(field.mas_centerY);
        make.right.mas_equalTo(field.mas_left);
    }];
    
    [field mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(fieldView.mas_centerX);
        make.centerY.mas_equalTo(fieldView.mas_centerY).with.offset(-10*kHeight);
        make.size.mas_equalTo(CGSizeMake(150*kWidth, 40*kHeight));
    }];
    
    UIButton * LeftBtn = [UIButton createUIbutton:@"" andFont:FontOfSize15 andColor:TitleColor];
    UIImageView * image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"guanbi"]];
    [_backField addSubview:image];
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(fieldView.mas_right).with.offset(-10*kWidth);
        make.centerY.mas_equalTo(label.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(15*kWidth, 15*kHeight));
    }];
    
    [LeftBtn addTarget:self action:@selector(pressQX) forControlEvents:UIControlEventTouchUpInside];
    [_backField addSubview:LeftBtn];
    
    [LeftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(fieldView.mas_right).with.offset(-10*kWidth);
        make.centerY.mas_equalTo(label.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(50*kWidth, 30*kHeight));
    }];
    
    UIButton * RightBtn = [UIButton createUIbutton:@"确定" andFont:FontOfSize15 andColor:WhiteColor];
    RightBtn.backgroundColor = YellowColor;
    [RightBtn addTarget:self action:@selector(pressQD) forControlEvents:UIControlEventTouchUpInside];
    [_backField addSubview:RightBtn];
    
    [RightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(fieldView.mas_centerX);
        make.bottom.mas_equalTo(fieldView.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(Main_Width-100*kWidth, 45*kHeight));
    }];
}

-(void)ProBackTouch{
    
    _backField.hidden = YES;
    [field resignFirstResponder];
}

// 取消
-(void)pressQX{
    
    _backField.hidden = YES;
    [field resignFirstResponder];
}

//确定
-(void)pressQD{
    
    priceStr = [NSString stringWithFormat:@"%@",field.text];
    if ([priceStr isEqualToString:@"0"]) {
        
        priceStr = @"0";
    }
    NSLog(@"%@",priceStr);
    NSString * str = [NSString stringWithFormat:@"%@ 元",priceStr];
    if (priceStr.length == 0) {
        NSString * standardSalePrice= [NSString stringWithFormat:@"%@ 元",_inforDic[@"standardSalePrice"]];
        str = standardSalePrice;
    }
    [priceBtn setTitle:str forState:UIControlStateNormal];
    _backField.hidden = YES;
    [field resignFirstResponder];
}


-(void)createScroll{
    
    
    _ScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 74*kHeight, Main_Width,Main_height-64*kHeight)];
    _ScrollView.contentOffset = CGPointMake(0, 0);
    _ScrollView.contentSize = CGSizeMake(Main_Width, 1.8*Main_height);
    _ScrollView.backgroundColor = UIviewBackColor;
    self.automaticallyAdjustsScrollViewInsets =NO;
    _ScrollView.bounces = NO;
    _ScrollView.userInteractionEnabled = YES;
    _ScrollView.showsHorizontalScrollIndicator = NO;
    _ScrollView.showsVerticalScrollIndicator = NO;
    _ScrollView.delegate = self;
    [self.view addSubview:_ScrollView];
    
}


-(void)createBackview1{
    
    _backview1 = [[UIView alloc]init];
    _backview1.backgroundColor = WhiteColor;
    [_ScrollView addSubview:_backview1];
    [_backview1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_ScrollView.mas_left);
        make.top.mas_equalTo(_ScrollView.mas_top);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 300*kHeight));
    }];
    
    UILabel * pricelabel = [UILabel createUIlabel:@"价格详情" andFont:FontOfSize14 andColor:PriceLabelColor];
    [_backview1 addSubview:pricelabel];
    [pricelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_backview1.mas_centerX);
        make.top.mas_equalTo(_backview1.mas_top).with.offset(25*kHeight);
    }];
    
    UIView * leftLine = [[UIView alloc]init];
    leftLine.backgroundColor = PriceLineColor;
    [_backview1 addSubview:leftLine];
    [leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview1.mas_left).with.offset(58*kWidth);
        make.centerY.mas_equalTo(pricelabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(91*kWidth, 0.5*kHeight));
    }];
    UIView * rightLine = [[UIView alloc]init];
    rightLine.backgroundColor = PriceLineColor;
    [_backview1 addSubview:rightLine];
    [rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right).with.offset(-58*kWidth);
        make.centerY.mas_equalTo(pricelabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(91*kWidth, 0.5*kHeight));
    }];
    
    NSString * standardSalePrice= [NSString stringWithFormat:@"%@",_inforDic[@"standardSalePrice"]];
    priceStr = standardSalePrice;

    standardPrice = [UILabel createUIlabel:standardSalePrice andFont:40.0 andColor:PriceBigColor];
    [_backview1 addSubview:standardPrice];
    [standardPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_backview1.mas_centerX);
        make.top.mas_equalTo(pricelabel.mas_bottom).with.offset(26*kWidth);
    }];
    UILabel * price1 = [UILabel createUIlabel:@"元" andFont:FontOfSize11 andColor:PriceBigColor];
    [_backview1 addSubview:price1];
    [price1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(standardPrice.mas_bottom);
        make.left.mas_equalTo(standardPrice.mas_right).with.offset(5*kWidth);
    }];
    UILabel * price2 = [UILabel createUIlabel:@"标准价格" andFont:FontOfSize11 andColor:PriceBigColor];
    [_backview1 addSubview:price2];
    [price2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(standardPrice.mas_bottom).with.offset(5*kHeight);
        make.centerX.mas_equalTo(_backview1.mas_centerX);
    }];

    PriceTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Main_Width, 86*kHeight) style:UITableViewStylePlain];
    [PriceTable setTableFooterView:[UIView new]];
    PriceTable.tag = 1000;
    PriceTable.delegate = self;
    PriceTable.dataSource = self;
    PriceTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    PriceTable.sectionIndexBackgroundColor= GrayColor;
    [_backview1 addSubview:PriceTable];
    [PriceTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview1.mas_left);
        make.top.mas_equalTo(price2.mas_bottom).with.offset(11*kHeight);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 99*kHeight));
    }];
    [PriceTable reloadData];

    UILabel * price3 = [UILabel createUIlabel:@"建议售价" andFont:FontOfSize13 andColor:PriceRedColor];
    [_backview1 addSubview:price3];
    [price3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview1.mas_left).with.offset(67*kWidth);
        make.top.mas_equalTo(PriceTable.mas_bottom).with.offset(22*kHeight);
    }];

    
    NSString * btnPirce = [NSString stringWithFormat:@"%@ 元",standardSalePrice];
    priceBtn = [UIButton createUIbutton:btnPirce andFont:FontOfSize15 andColor:YellowColor];
    [priceBtn addTarget:self action:@selector(pressPrice) forControlEvents:UIControlEventTouchUpInside];
    LRViewBorderRadius(priceBtn, 5, 0.5, YellowColor);
    //btn title 位置
//     [priceBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    [_backview1 addSubview:priceBtn];
    [priceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right).with.offset(-58*kWidth);
        make.centerY.mas_equalTo(price3.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(100*kWidth, 35*kHeight));
    }];

}

-(void)pressPrice{
    
    _backField.hidden = NO;
}


-(void)createBackview2{
    
    _backview2 = [[UIView alloc]init];
    _backview2.backgroundColor = WhiteColor;
    [_ScrollView addSubview:_backview2];
    [_backview2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_ScrollView.mas_left);
        make.top.mas_equalTo(_backview1.mas_bottom).with.offset(10*kHeight);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 750*kHeight));
    }];
    
    UILabel * pricelabel = [UILabel createUIlabel:@"物流详情" andFont:FontOfSize14 andColor:PriceLabelColor];
    [_backview2 addSubview:pricelabel];
    [pricelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_backview2.mas_centerX);
        make.top.mas_equalTo(_backview2.mas_top).with.offset(20*kHeight);
    }];
    
    UIView * leftLine = [[UIView alloc]init];
    leftLine.backgroundColor = PriceLineColor;
    [_backview2 addSubview:leftLine];
    [leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left).with.offset(58*kWidth);
        make.centerY.mas_equalTo(pricelabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(91*kWidth, 0.5*kHeight));
    }];
    UIView * rightLine = [[UIView alloc]init];
    rightLine.backgroundColor = PriceLineColor;
    [_backview2 addSubview:rightLine];
    [rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview2.mas_right).with.offset(-58*kWidth);
        make.centerY.mas_equalTo(pricelabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(91*kWidth, 0.5*kHeight));
    }];
    
    UIImageView * addressImage = [[UIImageView alloc]init];
    addressImage.image = [UIImage imageNamed:@"home_address"];
    [_backview2 addSubview:addressImage];
    [addressImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left).with.offset(24*kWidth);
        make.top.mas_equalTo(pricelabel.mas_bottom).with.offset(32*kHeight);
        make.size.mas_equalTo(CGSizeMake(10*kWidth, 15*kHeight));
    }];

    
    UILabel * addressLabel = [UILabel createUIlabel:@"运输地址" andFont:FontOfSize14 andColor:UIlabelColor];
    [_backview2 addSubview:addressLabel];
    [addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressImage.mas_right).with.offset(32*kWidth);
        make.centerY.mas_equalTo(addressImage.mas_centerY);
    }];
    
    UIImageView * begainAddressImage = [[UIImageView alloc]init];
    begainAddressImage.image = [UIImage imageNamed:@"home_yellow"];
    [_backview2 addSubview:begainAddressImage];
    [begainAddressImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left).with.offset(22*kWidth);
        make.top.mas_equalTo(addressImage.mas_bottom).with.offset(45*kHeight);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 6*kHeight));
    }];
    
//    NSString * begainadd = [NSString stringWithFormat:@"%@·%@·%@",_handDic[@"departRegionName"],_handDic[@"departContact"],_handDic[@"departPhone"]];

    NSString * departContact = [[Common shared] backString:_handDic[@"departContact"]];
    NSString * departPhone = [[Common shared] backString:_handDic[@"departPhone"]];

    NSString * begainadd = [NSString stringWithFormat:@"%@%@%@",_handDic[@"departRegionName"],departContact,departPhone];

    begainAddressLabel = [UILabel createUIlabel:begainadd andFont:FontOfSize14 andColor:UIlabelColor];
    [_backview2 addSubview:begainAddressLabel];
    [begainAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(begainAddressImage.mas_centerY);
    }];
    
    
    
    UIView * lineView1= [[UIView alloc]init];
    lineView1.backgroundColor = LineColor;
    [_backview2 addSubview:lineView1];
    [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(begainAddressLabel.mas_left);
        make.centerY.mas_equalTo(begainAddressLabel.mas_centerY).with.offset(15*kHeight);
        make.size.mas_equalTo(CGSizeMake(lineView_Width, 0.5*kHeight));
    }];
    

    UIImageView * endAddressImage = [[UIImageView alloc]init];
    endAddressImage.image = [UIImage imageNamed:@"home_blue"];
    [_backview2 addSubview:endAddressImage];
    [endAddressImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left).with.offset(24*kWidth);
        make.top.mas_equalTo(begainAddressImage.mas_bottom).with.offset(55*kHeight);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 6*kHeight));
    }];
    
    
//    NSString * destContact = [[Common shared] backString:_handDic[@"destContact"]];
//    NSString * destPhone = [[Common shared] backString:_handDic[@"destPhone"]];
    NSString * endadd = [NSString stringWithFormat:@"%@%@%@",_handDic[@"destRegionName"],_handDic[@"destContact"],_handDic[@"destPhone"]];

    endAddressLabel = [UILabel createUIlabel:endadd andFont:FontOfSize14 andColor:UIlabelColor];
    [_backview2 addSubview:endAddressLabel];
    [endAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(endAddressImage.mas_centerY);
    }];

    
    UIView * lineView2= [[UIView alloc]init];
    lineView2.backgroundColor = LineColor;
    [_backview2 addSubview:lineView2];
    [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(endAddressLabel.mas_left);
        make.centerY.mas_equalTo(endAddressLabel.mas_centerY).with.offset(15*kHeight);
        make.size.mas_equalTo(CGSizeMake(lineView_Width, 0.5*kHeight));
    }];
    
    
//    UIImageView * TimeImage = [[UIImageView alloc]init];
//    TimeImage.image = [UIImage imageNamed:@"home_time"];
//    [_backview2 addSubview:TimeImage];
//    [TimeImage mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(_backview2.mas_left).with.offset(22*kWidth);
//        make.top.mas_equalTo(endAddressImage.mas_top).with.offset(53*kHeight);
//        make.size.mas_equalTo(CGSizeMake(14*kWidth, 14*kHeight));
//    }];
//    
//    UILabel * TimeLabel = [UILabel createUIlabel:@"提车时间" andFont:FontOfSize14 andColor:UIlabelColor];
//    [_backview2 addSubview:TimeLabel];
//    [TimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(addressLabel.mas_left);
//        make.centerY.mas_equalTo(TimeImage.mas_centerY);
//    }];
//    
//    NSString * pickDate= [NSString stringWithFormat:@"%@",_handDic[@"pickDate"]];
//    chooseTimeLabel = [UILabel createUIlabel:pickDate andFont:FontOfSize14 andColor:UIlabelColor];
//    [_backview2 addSubview:chooseTimeLabel];
//    [chooseTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(addressLabel.mas_left);
//        make.centerY.mas_equalTo(TimeLabel.mas_centerY).with.offset(30*kHeight);
//    }];
//    
//
//    UIView * lineView3= [[UIView alloc]init];
//    lineView3.backgroundColor = LineColor;
//    [_backview2 addSubview:lineView3];
//    [lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(chooseTimeLabel.mas_left);
//        make.centerY.mas_equalTo(chooseTimeLabel.mas_centerY).with.offset(15*kHeight);
//        make.height.mas_equalTo(0.5*kHeight);
//        make.right.mas_equalTo(_backview2.mas_right);
//    }];
//    
    UIImageView * CarInforImage = [[UIImageView alloc]init];
    CarInforImage.image = [UIImage imageNamed:@"home_infor"];
    [_backview2 addSubview:CarInforImage];
    [CarInforImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left).with.offset(24*kWidth);
        make.centerY.mas_equalTo(lineView2.mas_centerY).with.offset(43*kHeight);
        make.size.mas_equalTo(CGSizeMake(14*kWidth, 14*kHeight));
    }];
    
    UILabel * carInforLabel = [UILabel createUIlabel:@"商品车信息" andFont:FontOfSize14 andColor:UIlabelColor];
    [_backview2 addSubview:carInforLabel];
    [carInforLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(CarInforImage.mas_centerY);
    }];
    

    CarInforTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Main_Width, 86*kHeight) style:UITableViewStylePlain];
    [CarInforTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    CarInforTable.tag = 2000;
    CarInforTable.delegate = self;
    CarInforTable.dataSource = self;
    CarInforTable.sectionIndexBackgroundColor= GrayColor;
    [_backview2 addSubview:CarInforTable];
    [CarInforTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left);
        make.top.mas_equalTo(carInforLabel.mas_bottom).with.offset(11*kHeight);
        make.size.mas_equalTo(CGSizeMake(Main_Width, [_handDic[@"orderSkuBOS"] count]*34*kHeight));
    }];
    
    [CarInforTable reloadData];

    
    UIImageView *PickCarInfor = [[UIImageView alloc]init];
    PickCarInfor.image = [UIImage imageNamed:@"pickcar"];
    [_backview2 addSubview:PickCarInfor];
    [PickCarInfor mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left).with.offset(24*kWidth);
        make.top.mas_equalTo(CarInforTable.mas_bottom).with.offset(30*kHeight);
        make.size.mas_equalTo(CGSizeMake(14*kWidth, 14*kHeight));
    }];
    
    UILabel * PickCarInforLabel = [UILabel createUIlabel:@"提车信息" andFont:FontOfSize14 andColor:UIlabelColor];
    [_backview2 addSubview:PickCarInforLabel];
    [PickCarInforLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(PickCarInfor.mas_centerY);
    }];
    

    NSString * str1 = nil;
    if ([_handDic[@"isDeliv"] isEqualToString:@"0"]) {
        str1 = @"物流点发车";
    }else{
        str1 = @"上门提车";
    }
    UILabel * type = [UILabel createUIlabel:str1 andFont:FontOfSize14 andColor:UIlabelColor];
    [_backview2 addSubview:type];
    [type mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(PickCarInforLabel.mas_centerY).with.offset(43*kHeight);
    }];
    
    NSString * str2 = [NSString stringWithFormat:@"%@  %@",_handDic[@"pickDate"],_handDic[@"pickTime"]];
    UILabel * time = [UILabel createUIlabel:str2 andFont:FontOfSize14 andColor:UIlabelColor];
    time.textAlignment = NSTextAlignmentRight;
    [_backview2 addSubview:time];
    [time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview2.mas_right).with.offset(-40*kWidth);
        make.centerY.mas_equalTo(type.mas_centerY);
    }];
    
    UIView * line1= [[UIView alloc]init];
    line1.backgroundColor = LineColor;
    [_backview2 addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(PickCarInforLabel.mas_left);
        make.right.mas_equalTo(_backview2.mas_right);
        make.centerY.mas_equalTo(type.mas_centerY).with.offset(15*kHeight);
        make.height.mas_equalTo(0.5*kHeight);
    }];
    
    

    
    UIImageView *handCarInfor = [[UIImageView alloc]init];
    handCarInfor.image = [UIImage imageNamed:@"handcar"];
    [_backview2 addSubview:handCarInfor];
    [handCarInfor mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left).with.offset(24*kWidth);
        make.top.mas_equalTo(type.mas_bottom).with.offset(30*kHeight);
        make.size.mas_equalTo(CGSizeMake(14*kWidth, 14*kHeight));
    }];
    
    UILabel * handCarInforLabel = [UILabel createUIlabel:@"交车信息" andFont:FontOfSize14 andColor:UIlabelColor];
    [_backview2 addSubview:handCarInforLabel];
    [handCarInforLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(handCarInfor.mas_centerY);
    }];

    NSString * str11 = nil;
    if ([_handDic[@"isDeliv"] isEqualToString:@"0"]) {
        str11 = @"物流点自提";
    }else{
        str11 = @"送车上门";
    }
    UILabel * type11 = [UILabel createUIlabel:str11 andFont:FontOfSize14 andColor:UIlabelColor];
    type11.textAlignment = NSTextAlignmentRight;

    [_backview2 addSubview:type11];
    [type11 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview2.mas_right).with.offset(-40*kWidth);
        make.centerY.mas_equalTo(handCarInforLabel.mas_centerY);
    }];
    
    UIView * line2= [[UIView alloc]init];
    line2.backgroundColor = LineColor;
    [_backview2 addSubview:line2];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(PickCarInforLabel.mas_left);
        make.right.mas_equalTo(_backview2.mas_right);
        make.centerY.mas_equalTo(type11.mas_centerY).with.offset(15*kHeight);
        make.height.mas_equalTo(0.5*kHeight);
    }];

    
    
    
    
    UIImageView *TypeCarInfor = [[UIImageView alloc]init];
    TypeCarInfor.image = [UIImage imageNamed:@"type"];
    [_backview2 addSubview:TypeCarInfor];
    [TypeCarInfor mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left).with.offset(24*kWidth);
        make.top.mas_equalTo(handCarInforLabel.mas_bottom).with.offset(30*kHeight);
        make.size.mas_equalTo(CGSizeMake(14*kWidth, 14*kHeight));
    }];
    
    UILabel * TypeCarInforLabel = [UILabel createUIlabel:@"运输方式" andFont:FontOfSize14 andColor:UIlabelColor];
    [_backview2 addSubview:TypeCarInforLabel];
    [TypeCarInforLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(TypeCarInfor.mas_centerY);
    }];
    
    NSString * str22 = nil;
    if ([_handDic[@"transportType"] isEqualToString:@"10"]) {
        str22 = @"大板车";
    }else{
        str22 = @"救援车";
    }
    UILabel * type22 = [UILabel createUIlabel:str22 andFont:FontOfSize14 andColor:UIlabelColor];
    [_backview2 addSubview:type22];
    type22.textAlignment = NSTextAlignmentRight;

    [type22 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview2.mas_right).with.offset(-40*kWidth);
        make.centerY.mas_equalTo(TypeCarInforLabel.mas_centerY);
    }];
    
    UIView * line3= [[UIView alloc]init];
    line3.backgroundColor = LineColor;
    [_backview2 addSubview:line3];
    [line3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(PickCarInforLabel.mas_left);
        make.right.mas_equalTo(_backview2.mas_right);
        make.centerY.mas_equalTo(type22.mas_centerY).with.offset(15*kHeight);
        make.height.mas_equalTo(0.5*kHeight);
    }];


    
    UIImageView *FaPiaoInfor = [[UIImageView alloc]init];
    FaPiaoInfor.image = [UIImage imageNamed:@"fapiao"];
    [_backview2 addSubview:FaPiaoInfor];
    [FaPiaoInfor mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left).with.offset(24*kWidth);
        make.top.mas_equalTo(TypeCarInforLabel.mas_bottom).with.offset(30*kHeight);
        make.size.mas_equalTo(CGSizeMake(14*kWidth, 14*kHeight));
    }];
    
    UILabel * FaPiaoLabel = [UILabel createUIlabel:@"发票" andFont:FontOfSize14 andColor:UIlabelColor];
    [_backview2 addSubview:FaPiaoLabel];
    [FaPiaoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(FaPiaoInfor.mas_centerY);
    }];
    
    NSString * str33 = [NSString stringWithFormat:@"%@",[[Common shared] backString:_handDic[@"companyName"]]];

    
    UILabel * type33 = [UILabel createUIlabel:str33 andFont:FontOfSize14 andColor:UIlabelColor];
    type33.textAlignment = NSTextAlignmentRight;
    [_backview2 addSubview:type33];
    [type33 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview2.mas_right).with.offset(-40*kWidth);
        make.centerY.mas_equalTo(FaPiaoInfor.mas_centerY);
    }];
    
    UIView * line4= [[UIView alloc]init];
    line4.backgroundColor = LineColor;
    [_backview2 addSubview:line4];
    [line4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(PickCarInforLabel.mas_left);
        make.right.mas_equalTo(_backview2.mas_right);
        make.centerY.mas_equalTo(type33.mas_centerY).with.offset(15*kHeight);
        make.height.mas_equalTo(0.5*kHeight);
    }];

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    UIImageView * remarksImage = [[UIImageView alloc]init];
    remarksImage.image = [UIImage imageNamed:@"beizhu"];
    [_backview2 addSubview:remarksImage];
    [remarksImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left).with.offset(24*kWidth);
        make.top.mas_equalTo(line4.mas_bottom).with.offset(30*kHeight);
        make.size.mas_equalTo(CGSizeMake(14*kWidth, 14*kHeight));
    }];
    
    UILabel * remarksLabel = [UILabel createUIlabel:@"备注" andFont:14 andColor:UIlabelColor];
    [_backview2 addSubview:remarksLabel];
    [remarksLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(remarksImage.mas_centerY);
    }];
    
    UITextView * InforField =[[UITextView alloc]init];
    InforField.frame = CGRectMake(14*kWidth, 64*kHeight, Main_Width-28*kWidth, 200*kWidth);
    InforField.delegate = self;
    InforField.userInteractionEnabled = NO;
    
    NSString * Field = [NSString stringWithFormat:@"%@",[[Common shared] backString:_handDic[@"comment"]]];
    if (Field.length == 0 || [Field isEqualToString:@"(null)"]) {
        Field = @"无";
    }
    
    InforField.text = Field;
    InforField.backgroundColor = GrayColor;
    InforField.font = Font(FontOfSize14);
    InforField.textColor = UITextColor;
    InforField.backgroundColor = UITextBackColor;
    InforField.textAlignment = NSTextAlignmentLeft;
    [_backview2 addSubview:InforField];
    [InforField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left).with.offset(24*kWidth);
        make.top.mas_equalTo(remarksLabel.mas_bottom).with.offset(18*kHeight);
        make.size.mas_equalTo(CGSizeMake(310*kWidth, 95*kHeight));
    }];
}



-(void)createBtn{
    
    
    UIButton * nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [nextBtn setTitle:@"确认发车" forState:UIControlStateNormal];
    [nextBtn setTitleColor:WhiteColor forState:UIControlStateNormal];
    [nextBtn addTarget:self action:@selector(pressNextBtn:) forControlEvents:UIControlEventTouchUpInside];
    nextBtn.layer.cornerRadius = 5;
    nextBtn.layer.borderWidth = 0.5;
    nextBtn.layer.borderColor = YellowColor.CGColor;
    nextBtn.backgroundColor = YellowColor;
    [_ScrollView addSubview:nextBtn];
    [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_ScrollView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(355*kWidth, 50*kHeight));
        make.top.mas_equalTo(_backview2.mas_bottom).with.offset(37*kHeight);
    }];
}


-(void)pressNextBtn:(UIButton*)sender{
    
    
    //判断同城返回空值
    NSString *insuranceUnitPrice = [NSString stringWithFormat:@"%@",[[Common shared] backString:_inforDic[@"insuranceUnitPrice"]]];
    NSString *insuranceSalePrice = [NSString stringWithFormat:@"%@",[[Common shared] backString:_inforDic[@"insuranceSalePrice"]]];
    NSString *distance = [NSString stringWithFormat:@"%@",[[Common shared] backString:_inforDic[@"mileage"]]];
    NSString *ltlUnitPrice = [NSString stringWithFormat:@"%@",[[Common shared] backString:_inforDic[@"ltlUnitPrice"]]];
    NSString *suggestSalePrice = [NSString stringWithFormat:@"%@",[[Common shared] backString:_inforDic[@"suggestSalePrice"]]];
    NSString *lineId = [NSString stringWithFormat:@"%@",[[Common shared] backString:_inforDic[@"lineId"]]];

    
    NSMutableDictionary * dic = _inforDic.mutableCopy;
    
    if (insuranceUnitPrice.length == 0) {
        [dic setObject:@"0" forKey:@"insuranceUnitPrice"];
    }
    if (insuranceSalePrice.length == 0) {
        [dic setObject:@"0" forKey:@"insuranceSalePrice"];
    }
    if (ltlUnitPrice.length == 0) {
        [dic setObject:@"0" forKey:@"ltlUnitPrice"];
    }
    if (suggestSalePrice.length == 0) {
        [dic setObject:@"0" forKey:@"suggestSalePrice"];
    }
    if (distance.length == 0) {
        [dic setObject:@"0" forKey:@"mileage"];
    }
    if (lineId.length == 0) {
        [dic setObject:@"0" forKey:@"lineId"];
    }

    [_handDic setObject:dic[@"insuranceUnitPrice"] forKey:@"insuranceUnitPrice"];
    [_handDic setObject:dic[@"insuranceSalePrice"] forKey:@"insuranceSalePrice"];

    //标准价
    [_handDic setObject:dic[@"standardSalePrice"] forKey:@"standardSalePrice"];
    //标准单公里运价 standardUnitPrice
    [_handDic setObject:dic[@"ltlUnitPrice"] forKey:@"standardUnitPrice"];
    //销售人员建议价格suggestSalePrice
    [_handDic setObject:priceStr forKey:@"suggestSalePrice"];
    //里程distance
    [_handDic setObject:dic[@"mileage"] forKey:@"distance"];
    //线路id  lineId
    [_handDic setObject:dic[@"lineId"] forKey:@"lineId"];

    //orderSkuBOS  商品车信息
    
    if (![self isPureInt:priceStr]) {
        
        [self createUIAlertController:@"请输入正确价格"];
    }else{
        NSMutableArray * arr = [[NSMutableArray alloc]init];
        arr = _handDic[@"orderSkuBOS"];
        
        
        NSData * jsonData = [NSJSONSerialization dataWithJSONObject:_handDic[@"orderSkuBOS"] options:NSJSONWritingPrettyPrinted error:nil];
        NSString * jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
        
        [_handDic setObject:jsonString forKey:@"orderSkuBOS"];
        
        WKProgressHUD * hud = [WKProgressHUD showInView:self.view withText:@"" animated:YES];        
        NSString *urlString = [NSString stringWithFormat:@"%@",Order_save];
        [Common afPostRequestWithUrlString:urlString parms:_handDic finishedBlock:^(id responseObj) {
            
            NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingMutableLeaves error:nil];
            
            
            NSLog(@"%@",dictionary[@"message"]);
            if ([dictionary[@"success"] boolValue]) {
                
                [self createUIAlertController1:dictionary[@"message"]];
                
            } else {
                
                [_handDic setObject:arr forKey:@"orderSkuBOS"];
                [WKProgressHUD popMessage:dictionary[@"message"] inView:self.view duration:1.5 animated:YES];
            }
            [hud dismiss:YES];
            
        } failedBlock:^(NSString *errorMsg) {
            NSLog(@"%@",errorMsg);
            
            [WKProgressHUD popMessage:errorMsg inView:self.view duration:1.5 animated:YES];
            [_handDic setObject:arr forKey:@"orderSkuBOS"];
        }];
        
        [_handDic setObject:arr forKey:@"orderSkuBOS"];
        
        NSLog(@"下一步");
    }
}


- (BOOL)isPureInt:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return[scan scanInt:&val] && [scan isAtEnd];
}



#pragma mark - 表单协议

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section{
    

    return tableView.tag == 1000 ? [_inforDic[@"feeBOS"] count] : [_handDic[@"orderSkuBOS"] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if (tableView.tag == 1000) {
        
        static NSString  *CellIdentifier = @"CellIdentifier";
        PriceCell * cell =  [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell ==nil) {
            cell = [[PriceCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.PriceLabel.text = [NSString stringWithFormat:@"%@",_inforDic[@"feeBOS"][indexPath.row][@"value"]];
        cell.PriceName.text = [NSString stringWithFormat:@"%@",_inforDic[@"feeBOS"][indexPath.row][@"name"]];
        return cell;
    }else{
        static NSString  *CellIdentifier = @"CellIdentifier";
        AddCarCell * cell =  [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell ==nil) {
            cell = [[AddCarCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.PlusImage.hidden = YES;
        cell.ReduceImage.hidden = YES;
        
        NSString * carStr = [NSString stringWithFormat:@"%@-%@",_handDic[@"orderSkuBOS"][indexPath.row][@"brandName"],_handDic[@"orderSkuBOS"][indexPath.row][@"seriesName"]];

        cell.CarName.text = carStr;
        cell.CarNumber.text = [NSString stringWithFormat:@"%@辆",_handDic[@"orderSkuBOS"][indexPath.row][@"amt"]];
        [cell.SmallImage sd_setImageWithURL:[NSURL URLWithString:_handDic[@"orderSkuBOS"][indexPath.row][@"brandLogoUrl"]] placeholderImage:[UIImage imageNamed:@"car_1"]];
        return cell;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return  33*kHeight;
}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    [field resignFirstResponder];
}

-(void)createUIAlertController1:(NSString*)title

{
    UIAlertController * alert =[UIAlertController alertControllerWithTitle:@"提示" message:title preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * action =[UIAlertAction actionWithTitle:@"返回首页" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        for (UIViewController *controller in self.navigationController.viewControllers) {
            if ([controller isKindOfClass:[HomeVC class]]) {
                [self.navigationController popToViewController:controller animated:YES];
            }
        }
        
    }];
    UIAlertAction * action1 =[UIAlertAction actionWithTitle:@"继续下单" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        

        if (_callBack) {
            self.callBack(YES);
        }
        [self.navigationController popViewControllerAnimated:YES];
  
    }];
    [alert addAction:action1];
    [alert addAction:action];
    [self presentViewController:alert animated:YES completion:nil];
}


-(void)createUIAlertController:(NSString*)title

{
    UIAlertController * alert =[UIAlertController alertControllerWithTitle:@"提示" message:title preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * action =[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction * action1 =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    [alert addAction:action1];
    [alert addAction:action];
    [self presentViewController:alert animated:YES completion:nil];
}


/* 解决触摸手势和cell点击的冲突 */
//- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
//    
//    if ([touch.view isEqual:_backField]) {
//        return YES;
//    }
//    return NO;
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
